<?php
/**
 * @author Ngo Minh Tri <minhtri2711@gmail.com>
 */
require_once APPPATH."controllers/cmsbase.php";

class cms_system extends CmsBase {
	var $_require_login = true;

	function __construct(){
		parent::__construct();
		$this->load->model('Model_sys', 'model_sys');
	}

	function index(){
		$users = $this->model_sys->fetch_all();
		$this->_render_my_view(array('users'=>$users));
	}

	function add(){
		if($this->input->post('Submit')){
			// validation
			$data = parse_input("item_", $_POST);
			// Check change passwd
			$this->model_sys->insert($data);
			redirect('cms_system/index', 'refresh');
		}
		return $this->_render_my_view();
	}

	function edit($id){
		if($this->input->post('Submit')){
			// validation
			$data = parse_input("item_", $_POST);
			// Check change passwd
			$this->model_sys->update($data, $id);
			redirect('cms_system/index', 'refresh');
		}
		$user = $this->model_sys->find($id);
		return $this->_render_my_view(array('user'=>$user));
	}

	function delete($id){
		$this->model_sys->delete($id);
		redirect('cms_system/index', 'refresh');
	}

}
?>
